import { Directive, Output, EventEmitter, Renderer2, ElementRef } from '@angular/core';

@Directive({
	selector: '[click.blur]'
})
export class ClickBlurDirective {
	@Output('click.blur') blurEvent = new EventEmitter();
	unsubscribe: () => void;

	constructor(
		private renderer: Renderer2, // Angular 2.x导入Renderer
		private element: ElementRef) {
	}

	ngOnInit() {
		this.unsubscribe = this.renderer.listen(
			this.element.nativeElement, 'click', event => {
				event.target.blur();
				this.blurEvent.emit(event);
			});
	}

	ngOnDestroy() {
		this.unsubscribe();
	}
}